package com.feidee.bigdata.service.impl;

import com.feidee.bigdata.dao.OrderDao;
import com.feidee.bigdata.domain.Order;
import com.feidee.bigdata.service.AccountService;
import com.feidee.bigdata.service.OrderService;
import com.feidee.bigdata.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author:CHQ
 * @Date:2020/5/11 18:25
 * @Description
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private StorageService storageService;
    @Autowired
    private AccountService accountService;

    @Override
    public void create(Order order) {
        System.out.println("开始创建订单");
        orderDao.create(order);
        System.out.println("创建订单完成");
        System.out.println("----------------------");
        System.out.println("开始减库存");
        storageService.decrease(order.getProductId(),order.getCount());
        System.out.println("减库存完成");
        System.out.println("----------------------");
        System.out.println("开始减账户金额");
        accountService.decrease(order.getUserId(),order.getMoney());
        System.out.println("减账户金额完成");
        System.out.println("----------------------");
        System.out.println("开始修改订单状态");
        orderDao.update(order.getUserId());
        System.out.println("修改订单状态完成");
    }
}
